#pragma once;

#include "Material.h"
#include "Vector3.h"

class  Metal :public Material
{
public:
	Vector3 albedo;
	float fuzz;

	Metal(const Vector3& a, float f) :
		albedo(a)
	{
		if (f >= 0 && f <= 1)
		{
			fuzz = f;
		}
		else if (f > 1) 
		{
			fuzz = 1;
		}
	}


	Vector3 Reflect(const Vector3& v, const Vector3& n) const
	{
		return v - 2 * dot(v, n)*n + fuzz * random_in_unit_sphere();
	}

	virtual bool scatter(const Ray& r_in, const HitRecord& rec, Vector3& attenuation, Ray& scattered) const
	{
		auto dir = unit_vector(r_in.direction());
		Vector3 reflect = Reflect(dir, rec.normal);



		scattered = Ray(rec.p, reflect);
		attenuation = albedo;
		return dot(scattered.direction(), rec.normal) > 0;
	}

};

